package sau.diyizu.media;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 @author JYD
 @version 1.0
 @since 2020/12/15 19:53 */
public interface ItemListener {
    int TYPE_DEFAULT = 0;
    int NO_POSITION = RecyclerView.NO_POSITION;

    default void onTrigger(RecyclerView.ViewHolder vh) {
        onTrigger(vh.itemView, vh.getAdapterPosition());
    }

    default void onTrigger(RecyclerView.ViewHolder vh, int type) {
        int pos = vh.getAdapterPosition();
        if (pos == NO_POSITION) return;
        onTrigger(vh.itemView, pos, type);
    }

    default void onTrigger(View view, int pos) {
        if (pos == NO_POSITION) return;
        onTrigger(view, pos, TYPE_DEFAULT);
    }

    void onTrigger(View view, int pos, int type);

    // 默认空实现， 可以有效减少判空代码
    ItemListener DEFAULT_NULL_INSTANCE = (view, pos, type) -> { };
}
